/*
 * PanelTowerSettingsDouble.cs
 *
 * Created on January 15, 2008, 1:21 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * Copyright (C) 2010       Mathijs Miermans
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


namespace HexTD
{
	public class PanelTowerSettingsDouble : PanelTowerSettings
	{

		private string[] modes1;
		private string[] modes2;
		private int mode1 = 0;
		private int mode2 = 0;
		private Tower t;
		private Context c;
		private bool loading = false;

		/** Creates new form PanelTowerSettingsDouble */
		public PanelTowerSettingsDouble(Tower t, Context c)
			: base(c)
		{
			this.c = c;
			initComponents();
			this.t = t;
		}
		public void setModes(string[] modes)
		{
			System.Diagnostics.Debug.WriteLine("PanelTowerSettingsDouble:setModes: should not be called for this class.");
		}
		public void setModes1(string[] modes)
		{
#if PORT
			this.loading = true;
			this.modes1 = modes;
			this.jComboBox_mode1.removeAllItems();
			for (int i=0; i<this.modes1.length; i++) {
				this.jComboBox_mode1.addItem(this.modes1[i]);
			}
			this.jComboBox_mode1.setSelectedIndex(this.mode1);
			this.jLabel_mode1.setText(this.modes1[this.mode1]);
			this.loading = false;
#endif
		}
		public void setModes2(string[] modes)
		{
#if PORT
			this.loading = true;
			this.modes2 = modes;
			this.jComboBox_mode2.removeAllItems();
			for (int i=0; i<this.modes2.length; i++) {
				this.jComboBox_mode2.addItem(this.modes2[i]);
			}
			this.jComboBox_mode2.setSelectedIndex(this.mode2);
			this.jLabel_mode2.setText(this.modes2[this.mode2]);
			this.loading = false;
#endif
		}
		public int getMode(int m)
		{
			if (m == 1)
			{
				return this.mode1;
			}
			else if (m == 2)
			{
				return this.mode2;
			}
			return -1;
		}

		public void setMode(int m, int v)
		{
#if PORT
			if (m == 1)
			{
				this.mode1 = v;
				this.loading = true;
				this.jComboBox_mode1.setSelectedIndex(this.mode1);
				this.jLabel_mode1.setText(this.modes1[this.mode1]);
				this.loading = false;
				if (t.getMode(1) != this.mode1) {
					t.setMode(1, this.mode1);
				}
			} else if (m==2) {
				this.mode2 = v;
				this.loading = true;
				this.jComboBox_mode2.setSelectedIndex(this.mode2);
				this.jLabel_mode2.setText(this.modes2[this.mode2]);
				this.loading = false;
				if (t.getMode(2) != this.mode2) {
					t.setMode(2, this.mode2);
				}
			}
#endif
		}

		public int nextMode(int m)
		{
			if (m == 1)
			{
				return this.nextMode1();
			}
			else if (m == 2)
			{
				return this.nextMode2();
			}
			else
			{
				return -1;
			}
		}
		public int nextMode1()
		{
#if PORT
			this.mode1++;
			if (this.mode1 >= this.modes1.length) {
				this.mode1 = 0;
			}
			this.loading = true;
			this.jComboBox_mode1.setSelectedIndex(this.mode1);
			this.jLabel_mode1.setText(this.modes1[this.mode1]);
			this.loading = false;
			t.setMode(1, this.mode1);
#endif
			return this.mode1;
		}
		public int nextMode2()
		{
#if PORT
			this.mode2++;
			if (this.mode2 >= this.modes2.length) {
				this.mode2 = 0;
			}
			this.loading = true;
			this.jComboBox_mode2.setSelectedIndex(this.mode2);
			this.jLabel_mode2.setText(this.modes2[this.mode2]);
			this.loading = false;
			t.setMode(2, this.mode2);
#endif
			return this.mode2;
		}

		public void setEnabled(bool enable)
		{
#if PORT
			this.jComboBox_mode1.setVisible(enable);
			this.jComboBox_mode2.setVisible(enable);
			this.jLabel_mode1.setVisible(!enable);
			this.jLabel_mode2.setVisible(!enable);
#endif
		}

		/** This method is called from within the constructor to
		 * initialize the form.
		 * WARNING: Do NOT modify this code. The content of this method is
		 * always regenerated by the Form Editor.
		 */
		// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
		private void initComponents()
		{
#if PORT
			java.awt.GridBagConstraints gridBagConstraints;

			jLabel1 = new javax.swing.JLabel();
			jComboBox_mode1 = new javax.swing.JComboBox();
			jComboBox_mode2 = new javax.swing.JComboBox();
			jLabel_mode1 = new javax.swing.JLabel();
			jLabel_mode2 = new javax.swing.JLabel();

			setLayout(new java.awt.GridBagLayout());

			setBackground(this.c.colors.getColorBackGround());
			setForeground(this.c.colors.getColorForeGround());
			jLabel1.setBackground(this.c.colors.getColorBackGround());
			jLabel1.setForeground(this.c.colors.getColorForeGround());
			jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
			jLabel1.setText("Target Modes");
			gridBagConstraints = new java.awt.GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			gridBagConstraints.gridwidth = 2;
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
			gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
			gridBagConstraints.weightx = 0.01;
			add(jLabel1, gridBagConstraints);

			jComboBox_mode1.setBackground(this.c.colors.getColorBackGround());
			jComboBox_mode1.setForeground(this.c.colors.getColorForeGround());
			jComboBox_mode1.setModel(new javax.swing.DefaultComboBoxModel(new string[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
			jComboBox_mode1.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent evt) {
					jComboBox_mode1ActionPerformed(evt);
				}
			});

			gridBagConstraints = new java.awt.GridBagConstraints();
			gridBagConstraints.gridx = 1;
			gridBagConstraints.gridy = 1;
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
			gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
			gridBagConstraints.weightx = 0.01;
			add(jComboBox_mode1, gridBagConstraints);

			jComboBox_mode2.setBackground(this.c.colors.getColorBackGround());
			jComboBox_mode2.setForeground(this.c.colors.getColorForeGround());
			jComboBox_mode2.setModel(new javax.swing.DefaultComboBoxModel(new string[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
			jComboBox_mode2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent evt) {
					jComboBox_mode2ActionPerformed(evt);
				}
			});

			gridBagConstraints = new java.awt.GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 1;
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
			gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
			gridBagConstraints.weightx = 0.01;
			add(jComboBox_mode2, gridBagConstraints);

			jLabel_mode1.setBackground(this.c.colors.getColorBackGround());
			jLabel_mode1.setForeground(this.c.colors.getColorForeGround());
			jLabel_mode1.setText("jLabel2");
			gridBagConstraints = new java.awt.GridBagConstraints();
			gridBagConstraints.gridx = 1;
			gridBagConstraints.gridy = 2;
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
			gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
			gridBagConstraints.weightx = 0.01;
			add(jLabel_mode1, gridBagConstraints);

			jLabel_mode2.setBackground(this.c.colors.getColorBackGround());
			jLabel_mode2.setForeground(this.c.colors.getColorForeGround());
			jLabel_mode2.setText("jLabel3");
			gridBagConstraints = new java.awt.GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 2;
			gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
			gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
			gridBagConstraints.weightx = 0.01;
			add(jLabel_mode2, gridBagConstraints);
#endif
		}// </editor-fold>//GEN-END:initComponents
#if PORT    
		private void jComboBox_mode1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_mode1ActionPerformed
			if (!this.loading) {
				this.mode1 = this.jComboBox_mode1.getSelectedIndex();
				this.c.setMode(this.t, 1, this.mode1);
			}
		}//GEN-LAST:event_jComboBox_mode1ActionPerformed
    
		private void jComboBox_mode2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_mode2ActionPerformed
			if (!this.loading) {
				this.mode2 = this.jComboBox_mode2.getSelectedIndex();
				this.c.setMode(this.t, 2, this.mode2);
			}
		}//GEN-LAST:event_jComboBox_mode2ActionPerformed
    
		// Variables declaration - do not modify//GEN-BEGIN:variables
		private javax.swing.JComboBox jComboBox_mode1;
		private javax.swing.JComboBox jComboBox_mode2;
		private javax.swing.JLabel jLabel1;
		private javax.swing.JLabel jLabel_mode1;
		private javax.swing.JLabel jLabel_mode2;
		// End of variables declaration//GEN-END:variables
#endif

	}
}